<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2019/1/9
 * Time: 20:32
 */
//创建Server对象，监听 127.0.0.1:9501端口
//$serv = new swoole_server("0.0.0.0", 9501);
$serv = new swoole_server("192.168.1.110", 9501);

//绑定参数
$serv->set([
    'worker_num' => 8 ,// worker进程数 cpu 1-4 倍
    'max_request' => 10000,
]);
//监听连接进入事件
/**
 * $fd 客户端id
 * $reactor_id 线程id
 */
$serv->on('connect', function ($serv, $fd ,$reactor_id) {
    echo "Client:{$fd};pid:{$reactor_id} Connect.\n";
});

//监听数据接收事件
$serv->on('receive', function ($serv, $fd, $from_id, $data) {
    $serv->send($fd, "send : {$fd} pid:{$from_id} Server: ".$data);
});

//监听连接关闭事件
$serv->on('close', function ($serv, $fd) {
    echo "Client{$fd}: Close.\n";
});

//启动服务器
$serv->start();
